/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tcnplanner;

import java.awt.Point;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Hashtable;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Koen
 */
public class ReservationTable extends AbstractTableModel {
    
    
    private Hashtable lookup;
    private final int rows;
    private final int columns;
    private final String headers[];
    private SimpleDateFormat sdf;

    public ReservationTable(ArrayList<Reservation> reservations) {
        
         sdf = new SimpleDateFormat("MM/dd/yy");
        rows = reservations.size();    
        
        String[] wtfheaders = {"ID", "DATE","Time", "Customer", "State"};
        headers = wtfheaders;
        columns = wtfheaders.length;
        
        int row = 0;
        lookup = new Hashtable();
        for(Reservation r : reservations){
            this.VulRegel(r,row);
            row++;
        }
            
        
    }
    // @res reservatie om in te vullen 
    // @row welke regel
    // methode zet vervolgens de reservatie.tostring, date, customer en status in de tabel
    public void VulRegel(Reservation res, int row){        
        setValueAt(res,row,0);        
        setValueAt(sdf.format(res.getReservationDate()),row,1);
        setValueAt(DateFormat.getTimeInstance(DateFormat.SHORT).format(res.getReservationDate()),row,2);
        setValueAt(res.getCustomer(),row,3);
        setValueAt(res.getStatus(),row,4);
        
    }

    public int getRowCount() {
        return rows;
    }

    public int getColumnCount() {
        return columns;
    }

    @Override
     public String getColumnName(int column) {
        return headers[column];
    }

    public Object getValueAt(int row, int column) {
        return lookup.get(new Point(row, column));
    }
    
    public Reservation getSelectedReservation(int selectedrow){
        return (Reservation)lookup.get(new Point(selectedrow,0));
    }

    @Override
    public void setValueAt(Object value, int row, int column) {
        if ((rows < 0) || (columns < 0)) {
            throw new IllegalArgumentException("Invalid row/column setting");
        }
        if ((row < rows) && (column < columns)) {
            lookup.put(new Point(row, column), value);
        }
        this.fireTableRowsUpdated(row, row);
        this.fireTableDataChanged();
    }
    
   
    
}
